home *** CD-ROM | disk | FTP | other *** search
-
- program plist(input, output);
- (* Pretty print with date/time stamp for Turbo Pascal programs.
- Written by: Rick Schaeffer
- E. 13611 26th Av.
- Spokane, Wa. 99216
-
- modifications (7/8/84 by Len Whitten, CIS: [73545,1006])
- 1) added error handling if file not found
- 2) added default extension of .PAS to main & include files
- 3) added "WhenCreated" procedure to extract file
- creation date & time from TURBO FIB
- 4) added demarcation of where include file ends
- 5) added upper char. conversion to include file
- 6) increased left margin to 5 spaces (80 char. line just fits @ 10cpi)
- 7) added listing control: {.L-} turns it off, {.L+} turns it back on,
- must be in column 1
-
- further modifications (7/12/84 by Rick Schaeffer)
- 1) cleaned up the command line parsing routines and put them in
- separate procedures. Now permits any number of command line
- arguments, each argument separated with at least one space.
- 2) added support for an optional second command line parameter
- which specifies whether include files will be listed or not.
- The command is invoked by placing "/i" on the command line
- at least one space after the file name to be listed. For
- instance, to list MYPROG.PAS as well as any "included" files,
- the command line would be: PLIST MYPROG /I
-
- Further modifications ( 4/22/85 by Steve Griffin )
- Changed the file date and time routines to go through
- DOS rather than use the FIB in Turbo. The FIB is set up
- differently for Turbo 3.0 and this version should work
- with Turbo 2.0 or 3.0 . I believe that Microsoft has made
- a change in DOS 3.x so that the success codes for file
- operations have changed from 2.x . Beware if you try to
- run this under DOS 3.x .
- *)
-
- type
- filrec = Record (* DTA layout *)
- file_ForD : array[1..21]of byte; (* reserved for DOS *)
- file_Attr : byte; (* file attribute *)
- file_Time : integer; (* file time *)
- file_Date : integer; (* file date *)
- file_Size : array[1..4] of byte; (* file size *)
- file_Name : array[1..13] of Char; (* file name *)
- file_Fill : array[1..85] of byte; (* filler - ????? *)
- End;
- fnmtype = string[14];
- instring = string[132];
- dtstr = string[8];
- two_letters = string[2];
- regpack = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
- end;
-
- const monthmask = $000F;
- daymask = $001F;
- minutemask = $003F;
- secondmask = $001F;
-
- var
- expand_includes : boolean;
- holdarg : instring;
- mainflnm : fnmtype;
- filefcb : filrec;
- linecnt, pageno,
- offset,i,j : integer;
- done : boolean;
- sysdate, systime,
- filedate, filetime : dtstr;
- month,day,year,
- hour,minute,second : two_letters;
- allregs : regpack;
-
- procedure fill_blanks (var line: dtstr);
-
- begin
- for i:= 1 to 8 do if line[i] = ' ' then line[i]:= '0';
- end; {fill_blanks}
-
- procedure getdate(var date : dtstr);
-
- begin
- allregs.ax := $2A * 256;
- MsDos(allregs);
- str((allregs.dx div 256):2,month);
- str((allregs.dx mod 256):2,day);
- str((allregs.cx - 1900):2,year);
- date := month + '/' + day + '/' + year;
- fill_blanks (date);
- end; {getdate}
-
- procedure gettime(var time : dtstr);
-
- begin
- allregs.ax := $2C * 256;
- MsDos(allregs);
- str((allregs.cx div 256):2,hour);
- str((allregs.cx mod 256):2,minute);
- str((allregs.dx div 256):2,second);
- time := hour + ':' + minute + ':' + second;
- fill_blanks (time);
- end; {gettime}
-
-
- procedure WhenCreated (var date, time: dtstr; var filename: fnmtype);
-
- var fulltime,fulldate,DTAds,DTAdx: integer;
- filesearch: fnmtype;
-
-
- Begin (* Get file date and time through DOS calls *)
- (* to make program independent of Turbo versions. *)
-
- (* Get current DTA and save location *)
-
- allregs.ax := $2F00;
- Intr($21,allregs);
- DTAds := allregs.es;
- DTAdx := allregs.bx;
-
- (* Set up DTA to recieve FCB of file. *)
-
- allregs.ax := $1A00;
- allregs.dx := ofs(filefcb);
- allregs.ds := Dseg;
- Intr($21,allregs);
-
- (* Search for file to print. *)
-
- allregs.ax := $4E00;
- allregs.cx := $37;
- filesearch := filename + chr(0);
- allregs.dx := ofs(filesearch) + 1;
- allregs.ds := Seg(filesearch);
- Intr($21,allregs);
- If Lo(allregs.ax) <> 0 then (* Note that PCDOS 3.x uses a *)
- (* different flag for successful *)
- (* file search, I believe. *)
- Begin
- Writeln(' File ',filename,' not found.');
- If Lo(allregs.ax) = 2 Then Writeln(' Drive not ready.');
- If Lo(allregs.ax) = 18 Then Writeln(' No file by that name');
- HALT;
- End;
-
- (* Restore DTA to previous location. *)
-
- allregs.ax := $1A00;
- allregs.dx := DTAdx;
- allregs.ds := DTAds;
- Intr($21,allregs);
-
- {fulldate corresponds to bytes 20-21
- of the FCB. Format is: bits 0 - 4: day of month
- 5 - 8: month of year
- 9 -15: year - 1980 }
-
- with filefcb do begin
- fulldate := file_Date;
- end;
- str(((fulldate shr 9) + 80):2,year);
- str(((fulldate shr 5) and monthmask):2,month);
- str((fulldate and daymask):2,day);
- date:= month + '/' + day + '/' + year;
- fill_blanks(date);
-
-
- {fulltime corresponds to bytes 22-23
- of the FCB. Format is: bits 0 - 4: seconds/2
- 5 -10: minutes
- 11-15: hours }
-
- with filefcb do begin
- fulltime := file_Time;
- end;
- str((fulltime shr 11):2,hour);
- str(((fulltime shr 5) and minutemask):2,minute);
- str(((fulltime and secondmask) * 2):2,second);
- time:= hour + ':' + minute + ':' + second;
- fill_blanks (time);
- end; {WhenCreated}
-
- function chkinc(var iptline : instring; var incflname : fnmtype) : boolean;
- var
- done : boolean;
- begin
- i := 4; j := 1; incflname := '';
- if copy(iptline, 1, 3) = '{$I' then begin
- i := 4; j := 1; incflname := '';
- while (iptline[i] = ' ') and (i <= length(iptline)) do i := i + 1;
- done := false;
- while not done do begin
- if i <= length(iptline) then begin
- if not (iptline[i] in [' ','}','+','-']) then begin
- incflname[j] := iptline[i];
- i := i + 1; j := j + 1;
- end else done := true;
- end else done := true;
- if j > 14 then done := true;
- end;
- incflname[0] := chr(j - 1);
- end;
- if incflname <> '' then chkinc := true else chkinc := false;
- end; {chkinc}
-
- procedure print_heading(filename : fnmtype);
-
- var offset_inc: integer;
-
- begin
- if linecnt <> 66 then write(lst,^L);
- pageno := pageno + 1;
- write(lst,' TURBO Pascal Program Lister');
- writeln(lst,' ':8,'Printed: ',sysdate,' ',systime,' Page ',pageno:4);
- if filename <> mainflnm then begin
- offset_inc:= 14 - length (filename);
- write(lst,' Include File: ',filename,' ':offset_inc,
- 'Created: ',filedate,' ',filetime);
- end
- else write(lst,' Main File: ',mainflnm,' ':offset,
- 'Created: ',filedate,' ',filetime);
- writeln(lst);
- writeln(lst); writeln(lst);
- linecnt := 1;
- end; {print_heading}
-
- procedure printline(iptline : instring; filename : fnmtype);
- begin
- if linecnt < 56 then begin
- writeln(lst,' ',iptline);
- linecnt := linecnt + 1;
- end else begin
- print_heading(filename);
- writeln(lst,' ',iptline);
- end;
- end; {printline}
-
- procedure listit(filename : fnmtype);
-
- var
- infile : text;
- iptline : instring;
- incflname : fnmtype;
- print : boolean;
-
- begin
- print:= true;
- assign(infile, filename);
- {$I-} reset(infile) {$I+} ;
- if IOresult <> 0 then begin
- writeln ('File ',filename,' not found.');
- halt;
- end;
- WhenCreated (filedate,filetime,filename);
- while not eof(infile) do begin
- readln(infile, iptline);
- if copy(iptline, 1, 4) = '{.L-' then print:= false;
- if print then begin
- if (chkinc(iptline, incflname) and (expand_includes)) then begin
- for i := 1 to length(incflname) do
- incflname[i] := upcase(incflname[i]);
- if pos('.',incflname) = 0 then incflname := incflname + '.PAS';
- printline('*************************************',filename);
- printline(' Including "'+incflname+'"', filename);
- printline('*************************************',filename);
- listit(incflname);
- printline('*************************************',filename);
- printline(' End of "'+incflname+'"', filename);
- printline('*************************************',filename);
- end {include file check}
- else begin
- if copy(iptline, 1, 4) = '{.PA' then print_heading(filename)
- else printline(iptline, filename);
- end {line printing}
- end {listing control}
- else if copy(iptline, 1, 4) = '{.L+' then print:= true;
- end; {file reading}
- close(infile);
- end; {listit}
-
- function parse_cmd(argno : integer) : instring;
- var
- i,j : integer;
- wkstr : instring;
- done : boolean;
- cmdline : ^instring;
- begin
- cmdline := ptr(CSEG,$0080);
- wkstr := '';
- done := false; i := 1; j := 0;
- if length(cmdline^) < i then done := true;
- repeat
- while ((cmdline^[i] = ' ') and (not done)) do begin
- i := i + 1;
- if i > length(cmdline^) then done := true;
- end;
- if not done then j := j + 1;
- while ((cmdline^[i] <> ' ') and (not done)) do begin
- wkstr := wkstr + cmdline^[i];
- i := i + 1;
- if i > length(cmdline^) then done := true;
- end;
- if (j <> argno) then wkstr := '';
- until (done or (j = argno));
- for i := 1 to length(wkstr) do
- wkstr[i] := upcase(wkstr[i]); {all arguments forced to upper case}
- parse_cmd := wkstr;
- end;
-
- begin {main program}
- getdate(sysdate);
- gettime(systime);
- linecnt := 66; pageno := 0;
- writeln;
- writeln('TURBO Pascal Formatted Listing');
- holdarg := parse_cmd(1); {get command line argument # 1}
- if length(holdarg) <= 14 then mainflnm := holdarg;
- holdarg := parse_cmd(2); {get optional command line argument # 2}
- if holdarg = '/I' then expand_includes := true
- else expand_includes := false;
- if mainflnm = '' then begin
- write('Enter file name: ');
- readln(mainflnm);
- end;
- if pos('.',mainflnm) = 0 then mainflnm := mainflnm + '.PAS';
- offset:= 24 - length (mainflnm);
- listit(mainflnm);
- write(lst,^L);
- write(lst,^L);
- end.
-